CREATE FUNCTION func_getDanhSachVatTuHangHoa()
RETURNS @temp TABLE 
(
 MaVatTu varchar(10),
 TenVatTu nvarchar(100),
 DonViTinh nvarchar(20)
)
AS
begin
	Declare @MaVatTu varchar(10),
			@TenVatTu nvarchar(100),
			@DonViTinh varchar(20),
			@curDanhSachVatTuHangHoa Cursor
	SET @curDanhSachVatTuHangHoa = CURSOR FOR
		SELECT MaVatTu, TenVatTu, DonViTinh = dbo.func_getDonViTinhMacDinh(MaVatTu) from VatTuHangHoa
		     
	OPEN @curDanhSachVatTuHangHoa
	FETCH NEXT FROM @curDanhSachVatTuHangHoa INTO @MaVatTu, @TenVatTu, @DonViTinh
	WHILE @@FETCH_STATUS = 0
	BEGIN
		Insert @temp values
			(
				@MaVatTu, @TenVatTu, @DonViTinh
			)
		FETCH NEXT FROM @curDanhSachVatTuHangHoa INTO @MaVatTu, @TenVatTu, @DonViTinh
	END
	
	RETURN
end
--
--////////////////////
--
CREATE FUNCTION func_getDanhSachKho()
RETURNS @temp TABLE 
(
 MaKho varchar(10),
 TenKho nvarchar(100)
)
AS
begin
	Declare @MaKho varchar(10),
			@TenKho nvarchar(100),
			@TenKhoKhongDau varchar(100),
			@curDanhSachKho Cursor
	SET @curDanhSachKho = CURSOR FOR
		SELECT * from Kho
		     
	OPEN @curDanhSachKho
	FETCH NEXT FROM @curDanhSachKho INTO @MaKho, @TenKho
	WHILE @@FETCH_STATUS = 0
	BEGIN
		set @TenKhoKhongDau = dbo.func_ChuyenCoDauThanhKhongDau(@TenKho)
		Insert @temp values
			(
				@MaKho, @TenKhoKhongDau
			)
		FETCH NEXT FROM @curDanhSachKho INTO @MaKho, @TenKho
	END
	
	RETURN
end